<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
const values = [
  10, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 0, 0, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10,
  0, 10, 10, 10, 10, 10, 0, 10, 0, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 0, 0, 10, 10, 0, 0,
  10, 10, 10, 10, 10, 10, 0, 0, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10,
  10, 10, 0, 0, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10,
  10, 0, 0, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  10, 0, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 0, 10, 0, 10, 10, 0, 10, 10, 10, 0, 0, 0, 10, 10, 10, 0, 10, 10, 10,
  0, 10, 10, 10, 0, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 10, 0, 10, 10, 10, 10, 10, 0, 10, 10, 0, 10, 10, 10, 10, 10,
  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 10, 0, 10,
  10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 10, 0, 10, 10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 10,
  10, 10, 10, 10, 0, 10, 10, 10, 0, 10, 10, 0, 0, 10, 10, 10, 10, 0, 0, 10, 0, 10, 10, 10, 10, 10
]


      function calculateMetrics(values) {
        // 统计总错误次数和总正确次数
        let totalErrors = 0
        let totalCorrects = 0

        // 统计连续错误段数和连续正确段数
        let totalErrorStreaks = 0
        let totalCorrectStreaks = 0

        // 统计在每次错误之前的正确次数
        let sumCorrectBeforeError = 0
        let countCorrectBeforeError = 0

        // 统计在每次正确之前的错误次数
        let sumErrorBeforeCorrect = 0
        let countErrorBeforeCorrect = 0

        // 当前连续错误和正确的计数
        let currentErrorStreak = 0
        let currentCorrectStreak = 0

        // 遍历数组
        for (let i = 0; i < values.length; i++) {
          const value = values[i]

          if (value === 0) {
            // 错误
            totalErrors += 1
            currentErrorStreak += 1

            // 如果之前有正确的连续段，记录下来
            if (currentCorrectStreak > 0) {
              sumCorrectBeforeError += currentCorrectStreak
              countCorrectBeforeError += 1
              currentCorrectStreak = 0
            }
          } else if (value === 10) {
            // 正确
            totalCorrects += 1
            currentCorrectStreak += 1

            // 如果之前有错误的连续段，记录下来
            if (currentErrorStreak > 0) {
              sumErrorBeforeCorrect += currentErrorStreak
              countErrorBeforeCorrect += 1
              currentErrorStreak = 0
            }
          }
        }

        // 处理最后一段
        if (currentErrorStreak > 0) {
          totalErrorStreaks += 1
        }
        if (currentCorrectStreak > 0) {
          totalCorrectStreaks += 1
        }

        // 统计连续错误段数和连续正确段数
        let lastValue = null
        for (let i = 0; i < values.length; i++) {
          const value = values[i]
          if (value === 0) {
            if (lastValue !== 0) {
              totalErrorStreaks += 1
            }
          } else if (value === 10) {
            if (lastValue !== 10) {
              totalCorrectStreaks += 1
            }
          }
          lastValue = value
        }

        // 计算平均连续错误次数
        const averageConsecutiveErrors = totalErrorStreaks > 0 ? (totalErrors / totalErrorStreaks).toFixed(2) : 0

        // 计算平均连续正确次数
        const averageConsecutiveCorrects =
          totalCorrectStreaks > 0 ? (totalCorrects / totalCorrectStreaks).toFixed(2) : 0

        // 计算平均连续正确多少次之后可能会错误
        const averageCorrectBeforeError =
          countCorrectBeforeError > 0 ? (sumCorrectBeforeError / countCorrectBeforeError).toFixed(2) : 0

        // 计算平均连续错误多少次之后可能会正确
        const averageErrorBeforeCorrect =
          countErrorBeforeCorrect > 0 ? (sumErrorBeforeCorrect / countErrorBeforeCorrect).toFixed(2) : 0

        return {
          averageConsecutiveErrors: parseFloat(averageConsecutiveErrors),
          averageConsecutiveCorrects: parseFloat(averageConsecutiveCorrects),
          averageCorrectBeforeError: parseFloat(averageCorrectBeforeError),
          averageErrorBeforeCorrect: parseFloat(averageErrorBeforeCorrect),
          totalErrorStreaks,
          totalCorrectStreaks,
          totalErrors,
          totalCorrects
        }
      }

      const metrics = calculateMetrics(values)
      console.log('平均连续错误次数:', metrics.averageConsecutiveErrors)
      console.log('平均连续正确次数:', metrics.averageConsecutiveCorrects)
      console.log('平均连续正确多少次之后可能会错误:', metrics.averageCorrectBeforeError)
      console.log('平均连续错误多少次之后可能会正确:', metrics.averageErrorBeforeCorrect)
      console.log('总错误次数:', metrics.totalErrors)
      console.log('总正确次数:', metrics.totalCorrects)
      console.log('总错误段数:', metrics.totalErrorStreaks)
      console.log('总正确段数:', metrics.totalCorrectStreaks)
    </script>
  </body>
</html>
